package com.upcoming.data.storm.caller;

import org.apache.storm.generated.GlobalStreamId;
import org.apache.storm.grouping.CustomStreamGrouping;
import org.apache.storm.task.WorkerTopologyContext;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 作者：tianjiayuan
 * 创建时间：2018-05-18 14:06
 * 类描述：
 * 修改人：
 * 修改时间：
 */
public class MyGrouping implements CustomStreamGrouping, Serializable {


    private int maxId = 0;

    public void prepare(WorkerTopologyContext workerTopologyContext, GlobalStreamId globalStreamId, List<Integer> list) {
        for (Integer id : list) {
            maxId = id < maxId ? maxId : id;
            System.out.println("taskId :" + id);
        }
    }

    public List<Integer> chooseTasks(int i, List<Object> list) {
        List<Integer> tasks = new ArrayList<>();
        tasks.add(maxId);
        return tasks;
    }
}
